using System;
using System.Configuration;

namespace KodeIT.Web.Configuration
{
    public sealed class HttpFilterElement : ConfigurationElement
    {
        #region Constants

        private const string PROPERTY_NAME = "name";
        private const string PROPERTY_TYPE = "type";

        #endregion

        #region Statics

        private static ConfigurationProperty _propName;
        private static ConfigurationProperty _propType;
        private static readonly ConfigurationPropertyCollection _properties;

        static HttpFilterElement()
        {
            _propName = new ConfigurationProperty(
                PROPERTY_NAME, typeof(string), null, ConfigurationPropertyOptions.IsRequired);

            _propType = new ConfigurationProperty(
                PROPERTY_TYPE, typeof(string), null, ConfigurationPropertyOptions.IsRequired);

            _properties = new ConfigurationPropertyCollection();
            _properties.Add(_propName);
            _properties.Add(_propType);
        }

        #endregion

        #region Properties

        [ConfigurationProperty(PROPERTY_NAME, IsKey = true, IsRequired = true)]
        public string Name
        {
            get { return (string)this[PROPERTY_NAME]; }
            set { this[PROPERTY_NAME] = value; }
        }

        [ConfigurationProperty(PROPERTY_TYPE, IsRequired = true)]
        public string Type
        {
            get { return this[PROPERTY_TYPE] as string; }
            set { this[PROPERTY_TYPE] = value; }
        }

        protected override ConfigurationPropertyCollection Properties
        {
            get { return _properties; }
        }

        #endregion
    }
}
